package api

import (
	"github.com/gin-gonic/gin"
	"go-learn/dao"
	demo3 "go-learn/model/pb"
	demo2 "go-learn/model/request"
	"go-learn/model/response"
)

func Insert(c *gin.Context) {
	var data demo3.User
	_ = c.ShouldBind(&data)
	err := dao.Insert(data)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func InsertAll(c *gin.Context) {
	var data []demo3.User
	_ = c.ShouldBind(&data)
	err := dao.InsertAll(data)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func DeleteUserById(c *gin.Context) {
	var data demo3.User
	_ = c.ShouldBind(&data)
	err := dao.DeleteUserById(data.Id)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func UpdateAgeById(c *gin.Context) {
	var data demo3.User
	_ = c.ShouldBind(&data)
	err := dao.UpdateAgeById(data)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func SelectUserById(c *gin.Context) {
	var data demo3.User
	_ = c.ShouldBind(&data)
	user, err := dao.SelectUserById(data.Id)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(user, c)
}
func SelectUserPage(c *gin.Context) {
	var data demo2.UserPageQuery
	_ = c.ShouldBind(&data)
	users, err := dao.SelectUserPage(data)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(users, c)
}
